import Reflux from 'reflux';
import PageConst from './PageConst';
import Actions from './Actions';
import update from 'react-addons-update';
import nattyStorage from 'natty-storage';
import DB from '../../app/db';

export default Reflux.createStore({
  listenables: [Actions],
  data: {
    ...PageConst,
    iosShow: false,
    auto_show:false,
    menus: [{
      label: 'PM2.5',
      onClick: ()=> {Actions.orderByPm()}
    }, {
      label: '噪音',
      onClick: ()=> {Actions.orderByZaoyin()}
    }],
    act: [
      {
        label: '取消',
        onClick: ()=> {Actions.closeActionSheet()}
      }
    ]
  },

  onShowActionSheet:function(){
    this.data.iosShow = update(this.data.iosShow, {$set: true});
    this.updateComponent();
  },

  onCloseActionSheet:function(){
    this.data.iosShow = update(this.data.iosShow, {$set: false});
    this.data.auto_show = update(this.data.auto_show, {$set: false});
    this.updateComponent();
  },

  onOrderByPm:function(){
    alert("根据pm2.5排序");
    this.onCloseActionSheet();
  },

  onOrderByZaoyin:function(){
    alert("根据噪音排序");
    this.onCloseActionSheet();
  },

  onFetch: function (params, cb) {
    let t = this;
    t.updateComponent();
    cb && cb(t.data);
  },

  updateComponent: function () {
    this.trigger(this.data);
  },

  getInitialState: function () {
    return this.data;
  }
});
